<%--
  Created by IntelliJ IDEA.
  User: 陈熠
  Date: 2017/7/10
  Time: 17:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>表格控件</title>
    <%@ include file="/common/jsp/resource.jsp" %>
    <script type="text/javascript" src="/page/code/js/list.js"></script>
</head>
<body>
<div class="layui-input-inline">
    <button class="layui-btn" onclick="submitCode()">提交代码(表格代码示例)</button>
</div>
<div class="layui-tab">
    <ul class="layui-tab-title">
        <li class="layui-this">代码</li>
        <li>效果</li>
        <li>参数详解</li>

    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <code style="margin-top: 4px; display: block;">表格代码示例</code>
            <textarea class="layui-textarea" rows="18">
            <div class="layui-form ">
                <table class="layui-table" id="demo" cyType="pageGrid"
                       cyProps="url:'/sys/code/list',checkbox:'true',pageColor:'#2991d9'">
                    <thead>
                        <tr>
                           <!--复选框-->
                           <th width="1%" param="{type:'checkbox'}">
                               <input type="checkbox" lay-skin="primary" lay-filter="allChoose">
                           </th>
                          <!--isPrimary：是否是主键-->
                           <th width="10%" param="{name:'id',isPrimary:'true',hide:'true'}">菜单ID</th>
                           <th width="10%" param="{name:'codeName'}">编码名</th>
                           <%--<th param="{name:'codeName'}">编码名称</th>--%>
                           <th width="10%" param="{name:'code'}">参数值</th>
                           <th width="10%" param="{name:'value'}">参数名</th>
                           <th width="10%" param="{name:'status',render:'Render.customState'}">状态</th>
                           <th width="10%" param="{name:'name'}">名称</th>
                           <th width="10%" param="{name:'remark'}">备注</th>
                         </tr>
                    </thead>
                </table>
            </div>
           </textarea>
            <code style="margin-top: 4px; display: block;">查询表单示例</code>
            <textarea class="layui-textarea" rows="15">
            <form class="layui-form " action="">
                <div class="layui-form-item"><label class="layui-form-label">参数名:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" placeholder="请输入参数名" class="layui-input">
                    </div>
                    <div class="layui-input-inline">
                        <button class="layui-btn" table-id="demo" lay-submit="" lay-filter="search"><i
                                class="fa fa-search">&nbsp;</i>查询</button>
                        <button type="reset" class="layui-btn layui-btn-primary"><i
                                class="fa fa-refresh">&nbsp;</i>重置</button>
                    </div>
                </div>
            </form>
         </textarea>
            <code style="margin-top: 4px; display: block;">Render.customState示例</code>
            <textarea class="layui-textarea" rows="15">
           //数据渲染对象
           var Render = {
               customState: function (rowdata, index, value) {
               if(value === 1){
                  return '<span class="layui-btn layui-btn-mini layui-btn-green">正常</span>';
                }
               if(value === 0){
                 return '<span class="layui-btn layui-btn-mini layui-btn-danger">禁用</span>';
               }
                 return value;
               },
            };
         </textarea>

        </div>
        <div class="layui-tab-item" id="result">
            <div class="layui-form ">
                <div class="layui-form ">
                    <table class="layui-table" id="demo" cyType="pageGrid"
                           cyProps="url:'/sys/code/list',checkbox:'true',pageColor:'#2991d9'">
                        <thead>
                        <tr>
                            <!--复选框-->
                            <th width="1%" param="{type:'checkbox'}">
                                <input type="checkbox" lay-skin="primary" lay-filter="allChoose">
                            </th>
                            <!--isPrimary：是否是主键-->
                            <th width="10%" param="{name:'id',isPrimary:'true',hide:'true'}">菜单ID</th>
                            <th width="10%" param="{name:'codeName'}">编码名</th>
                            <%--<th param="{name:'codeName'}">编码名称</th>--%>
                            <th width="10%" param="{name:'code'}">参数值</th>
                            <th width="10%" param="{name:'value'}">参数名</th>
                            <th width="10%" param="{name:'status',render:'Render.customState'}">状态</th>
                            <th width="10%" param="{name:'name'}">名称</th>
                            <th width="10%" param="{name:'remark'}">备注</th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
        <div class="layui-tab-item">
            <table class="layui-table">
                <thead>
                <tr>
                    <th>表格参数</th>
                    <th>描述</th>
                    <th>默认值</th>
                    <th>代码示例</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>id</td>
                    <td>表格id,用于查询表单关联</td>
                    <td><span style="color:red">必填</span></td>
                    <td>id="demo" || &lt;button table-id="demo"&gt;查询&lt;/button&gt;</td>
                </tr>
                <tr>
                    <td>cyType</td>
                    <td>控件类型</td>
                    <td><span style="color:red">必填</span></td>
                    <td>cyType="pageGrid"</td>
                </tr>
                <tr>
                    <td>cyProps:url</td>
                    <td>数据源</td>
                    <td><span style="color:red">必填</span></td>
                    <td> cyProps="url:'/syscode/list'"</td>
                </tr>
                <tr>
                    <td>cyProps:checkbox</td>
                    <td>是否开启复选框</td>
                    <td>true</td>
                    <td>yProps="checkbox:'true'"</td>
                </tr>
                <tr>
                    <td>cyProps:pageColor</td>
                    <td>分页样式</td>
                    <td>#2991d9</td>
                    <td>cyProps="pageColor:'#2991d9'"</td>
                </tr>
                <tr>
                    <td>cyProps:pageSize</td>
                    <td>每页显示条数</td>
                    <td>10</td>
                    <td>cyProps="pageSize:'20'"</td>
                </tr>
                </tbody>
            </table>
            <table class="layui-table">
                <thead>
                <tr>
                    <th>列参数</th>
                    <th>描述</th>
                    <th>默认值</th>
                    <th>代码示例</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>param.name</td>
                    <td>字段值</td>
                    <td><span style="color:red">必填</span></td>
                    <td>param="{name:'code'}"</td>
                </tr>
                <tr>
                    <td>param.isPrimary</td>
                    <td>该字段是否是主键,勾选复选框时对应的值</td>
                    <td>false</td>
                    <td>param="{isPrimary:'true'}"</td>
                </tr>
                <tr>
                    <td>param.hide</td>
                    <td>是否隐藏</td>
                    <td>false</td>
                    <td>param="{hide:'true'}"</td>
                </tr>
                <tr>
                    <td>param.render</td>
                    <td>渲染列,用于修改该列的数据</td>
                    <td>null</td>
                    <td>param="{render:'Render.customState'}"</td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
</div>
<script>
    layui.use('element', function () {
    });
    function submitCode() {
        var code = $("textarea").val();
        $("#result").html(code);
        $("#result").find("#demo").pageGrid();
        alert("代码提交成功,请查看效果!");
    }
</script>
</body>
</html>
